/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ejb;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import com.entity.Temas;
import javax.persistence.Query;
import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException;
/**
 *
 * @author victor
 */
@Stateless
public class TemasFachadaBean implements TemasFachadaRemote, TemasFachadaLocal {
    @PersistenceContext
    private EntityManager em;

    public void persist(Object object) {
        em.persist(object);
    }

    public Temas ExisteTema(String Interprete, String Cancion) {

        Query miConsulta =  em.createNamedQuery("Temas.ExisteTema");
        miConsulta.setParameter("Interprete",Interprete);
        miConsulta.setParameter("Cancion",Cancion);
        Temas miTema = null ;
        try
        {
            miTema = (Temas)miConsulta.getSingleResult();

        }catch ( NoResultException e ){}
         catch ( NonUniqueResultException e) {}
        
        return miTema;

     
    }

    public void borrarTema(Long IDTema) {
        Query miConsulta =  em.createNamedQuery("Temas.Borrar");
        miConsulta.setParameter("IDTema",IDTema);

        try
        {

            miConsulta.executeUpdate();

        }catch ( NoResultException e){}
        return;
    }


    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method" or "Web Service > Add Operation")
 
}
